//
//  TestViewController5.swift
//  demo01
//
//  Created by babybus on 2025/6/30.
//
import Foundation
import UIKit
import SnapKit


class LHPage:UIViewController{
    private var pageView:UIView = UIView()
    private var infoView:UIView = UIView()
    private var initialUserInfo:InitialUserInfoStack!   //首部用户信息
    private var userAppInfo:UserAppInfoStack!        //用户在APP中的信息
    private var openVip:OpenVipView!            //VIP开通栏
    private var moduleList:ModuleCollection!    //模块列表
    private var taskList:TaskCollection!        //任务列表
    
    override func viewDidLoad(){
        
        //首部用户信息 -- initialUserInfo
        initialUserInfo = InitialUserInfoStack();
//        pageView.addSubview(initialUserInfo)
        infoView.addSubview(initialUserInfo)
        initialUserInfo.snp.makeConstraints({make in
//            make.top.equalToSuperview().inset(0)//44
            make.top.equalToSuperview().inset(44)//44
            make.width.equalTo(375)
            make.left.equalTo(10)
            make.right.equalTo(-10)
            make.height.equalTo(44)
        })//y=88
        //用户App使用信息 -- userAppInfo
        userAppInfo = UserAppInfoStack();
//        pageView.addSubview(userAppInfo)
        infoView.addSubview(userAppInfo)
        userAppInfo.snp.makeConstraints({make in
            make.top.equalTo(initialUserInfo.snp.bottom).inset(-15)//103
            make.left.equalTo(12)
            make.height.equalTo(100)
        })//y=203
        
        //开通会员 -- openVIP
        openVip = OpenVipView();
//        pageView.addSubview(openVip)
        infoView.addSubview(openVip)
        openVip.snp.makeConstraints({make in
            make.top.equalTo(userAppInfo.snp.bottom).inset(-12)//215
            make.left.equalToSuperview().inset(12)
            make.right.equalToSuperview().inset(12)
            make.width.equalTo(351)
            make.height.equalTo(42)
        })//y=257
        
        //任务列表 -- taskList
        taskList = TaskCollection()
        pageView.addSubview(taskList)
        taskList.snp.makeConstraints { make in
//            make.top.equalTo(openVip.snp.bottom).inset(-12)//269
            make.top.equalToSuperview().inset(-12)
            make.left.equalTo(12)
            make.right.equalTo(-12)
            make.height.equalTo(226.5)
            make.width.equalTo(351)
        }//y=495.5
        
        //模块列表 -- moduleList
        moduleList = ModuleCollection()
        pageView.addSubview(moduleList)
        moduleList.snp.makeConstraints { make in
            make.top.equalTo(taskList.snp.bottom).inset(-12.5)//508
            make.left.equalTo(12)
            make.right.equalTo(-12)
            make.width.equalTo(351)
            make.height.equalTo(215)
        }
        
        
        //infoView + pageView
        setBackGround(view: infoView, background: UIImageView(image: UIImage(named: "./背景-渐变蓝色")))
        pageView.backgroundColor = .systemGray6
        self.view.addSubview(infoView)
        self.view.addSubview(pageView)
        infoView.snp.makeConstraints { make in
            make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
            make.width.equalToSuperview()
            make.height.equalTo(274)
        }
        pageView.snp.makeConstraints { make in
            make.top.equalTo(infoView.snp.bottom)
            make.width.equalToSuperview()
            make.height.equalTo(538)
        }
        
    }
    func setBackGround(view:UIView ,background:UIImageView){
        background.contentMode = .scaleAspectFit//支持按比例缩放
        background.clipsToBounds = true//不超出界限
        
        view.insertSubview(background, at: 0)//插入最底部
        background.snp.makeConstraints { make in
            make.edges.equalToSuperview()//铺满父容器
        }
    }
}
